package com.letoken.platform.pub.annotation.sms;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class SpecifyValidator implements ConstraintValidator< SpecifyMatch, Object> {
    private String[] strValues;
    private int[] intValues;


    @Override
    public void initialize(SpecifyMatch constraintAnnotation) {
        strValues = constraintAnnotation.strValues();
        intValues = constraintAnnotation.intValues();
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context ) {
        if(value instanceof String) {
            for (String s:strValues) {
                if(s.equals(value)){
                    return true;
                }
            }
        }else if(value instanceof Integer){
            for (Integer s:intValues) {
                if(s==value){
                    return true;
                }
            }
        }
        return false;
    }

}
